package com.eorchis.module.classauditinfo.ui.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eorchis.core.service.IBaseService;
import com.eorchis.core.ui.commond.ResultState;
import com.eorchis.core.ui.controller.AbstractBaseController;


import com.eorchis.module.classauditinfo.querybean.ClassAuditInfoQueryBean;
import com.eorchis.module.classauditinfo.service.IClassAuditInfoService;
import com.eorchis.module.classauditinfo.ui.commond.ClassAuditInfoQueryCommond;
import com.eorchis.module.classauditinfo.ui.commond.ClassAuditInfoValidCommond;
import com.eorchis.utils.utils.PropertyUtil;

/**
 * Title: ClassAuditInfoController<br>
 * Description: 班级审核信息管理控制器<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * @author Max
 * @createDate 2013-12-31
 * @version $Revision$
 */
@Controller("classAuditInfoController")
@RequestMapping(value = ClassAuditInfoController.MODULE_PATH)
public class ClassAuditInfoController 
		extends AbstractBaseController<ClassAuditInfoValidCommond,ClassAuditInfoQueryCommond> 
{
	// 模块页面根路径
	public static final String MODULE_PATH = "/module/classauditinfo";
	// 班级审核信息接口
	@Autowired
	@Qualifier("com.eorchis.module.classauditinfo.service.impl.ClassAuditInfoServiceImpl")
	private IClassAuditInfoService classAuditInfoService;
	
	public IBaseService getService() {
		return classAuditInfoService;
	}

	public String getModulePath() {
		return MODULE_PATH;
	}
	/**
	 * 获取班级审核信息
	 * @param qCommond
	 * @param bindingResult
	 * @param request
	 * @param response
	 * @param resultState 
	 * @return
	 * @throws Exception
	 * @author Max
	 * @createDate 2014-12-15
	 */
	@RequestMapping(value = "/findAuditInfo")
	public String findAuditInfo(@ModelAttribute("result") ClassAuditInfoValidCommond commond,HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState) throws Exception{
		String classId=commond.getClassId();
		if(PropertyUtil.objectNotEmpty(classId)) {
			//获取班级审核信息
			ClassAuditInfoQueryCommond qCommond=new ClassAuditInfoQueryCommond();
			qCommond.setSearchClassId(classId);
			List<ClassAuditInfoValidCommond> list=(List<ClassAuditInfoValidCommond>) classAuditInfoService.findAllList(qCommond);
			if(list!=null&&list.size()>0) {
				ClassAuditInfoValidCommond co=list.get(0);
			}
			resultState.setState(ResultState.RESULT_STATE_SUCCESS);
		}else {
			resultState.setMessage("培训班ID为空");
			resultState.setState(ResultState.RESULT_STATE_FAIL);
		}
		return "";
	}
	/**
	 * 获取班级审核信息
	 * @param qCommond
	 * @param bindingResult
	 * @param request
	 * @param response
	 * @param resultState 
	 * @return
	 * @throws Exception
	 * @author Xupp
	 * @createDate 2015-1-27
	 */
	@RequestMapping(value = "/getAuditInfoByclassId")
	public String getAuditInfoByclassId(@ModelAttribute("result") ClassAuditInfoValidCommond commond
			,HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState) throws Exception{
		String classId=commond.getClassId();
		if(PropertyUtil.objectNotEmpty(classId)) {
			//获取班级审核信息
			ClassAuditInfoQueryBean  caiqb=classAuditInfoService.getAuditInfoByClassId(commond);
			if(PropertyUtil.objectNotEmpty(caiqb)){
				commond.setAuditReason(caiqb.getAuditReson());
				commond.setCreateDate(caiqb.getCreateDate());
			}
			resultState.setState(ResultState.RESULT_STATE_SUCCESS);
		}else {
			resultState.setMessage("培训班ID为空");
			resultState.setState(ResultState.RESULT_STATE_FAIL);
		}
		return "";
	}
}
